using System;
using System.Collections.Generic;
using System.Reflection;
using System.Reflection.Emit;
using rpc_service.core.support.assembly.roslyn;

namespace rpc_service.core.support.assembly;

public class DynamicClassGenerator
{
    private RPCGenerate<RoslynStep> _roslynGenerate = new RoslynGenerate();
    private RPCClassLoader _rpcClassLoader = new RPCClassLoader();
    
    public IDictionary<string, object> Generate()
    {
        List<Type> typs = _rpcClassLoader.ClassLoader();
        IDictionary<string, object> objects = new Dictionary<string, object>();
            
        foreach (Type type in typs)
        { 
            objects.Add(type.Name, GenerateDynamicProxy(type));
        }
        
        return objects;
    }
    
    /// <summary>
    /// 通过接口生成实体类
    /// </summary>
    /// <param name="targetType"></param>
    /// <returns></returns>
    private object GenerateDynamicProxy(Type targetType)
    {
        return _roslynGenerate.Generate(targetType);
    }
}